<script>
import {getShipmentA4PDFById} from "@/api/shipment";

export default {
  name: "ExportShipmentA4",
  props:{
    shipment: {
      type: Object,
      required: true,
    }
  },
  data(){
    return {
      loading: false
    }
  },
  methods:{
    getShipmentA4PDF(){
      this.loading = true
      getShipmentA4PDFById(this.shipment.id)
        .then(res=>{
          this.loading = false
          const pdfFile = window.URL.createObjectURL(
            new Blob([res.data], { type: "application/pdf" })
          );

          // 跳转页面预览
          window.open(pdfFile);
          // 60秒后释放
          setTimeout(()=>{
            URL.revokeObjectURL(pdfFile); //释放URL对象
          },60000)
        })
    }
  }
}
</script>

<template>
  <el-button
    :loading="loading"
    @click="getShipmentA4PDF"
    type="primary"
  >{{$t('common.export')}}</el-button>
</template>

<style scoped lang="scss">

</style>
